﻿using UnityEngine;
using System.Collections;
using System.IO;
using Newtonsoft.Json;
public class ResMgr : Singleton<ResMgr>
{
    
    public string doc_path
    {
        get
        {
#if UNITY_EDITOR || UNITY_STANDALONE
            return Application.streamingAssetsPath;
#else
            return Application.persistentDataPath;
#endif

        }
    }
    public void Init()
    {
#if UNITY_ANDROID
        InitMobileData();
#endif
    }
    public T  LoadJsonData<T>() where T:class
    {
        var fileName =  typeof(T).Name + ".json";
        string path = doc_path + "/" + fileName;
        if (File.Exists(path))
        {
            
            var json = File.ReadAllText(path);
            var objData  = JsonConvert.DeserializeObject<T>(json);

            Log.InfoFormat("Load {0}  Json Data : \n {1}" ,Log.Color_Orange,fileName, objData.ToString());
            return objData;
        }
        return null;
    }
    public void SaveJsonData<T>(T data)
    {
        var fileName = typeof(T).Name + ".json";
        var json = JsonConvert.SerializeObject(data,Formatting.Indented);
        Log.InfoFormat(" \n Save {0}  Json Data : {1}", Log.Color_Orange,fileName, json);
        string path = doc_path + "/" + fileName;
        File.WriteAllText(path,json);
    }
    /// <summary>
    /// CopyStreamming 的 数据 到persistentData 
    /// </summary>
    public void InitMobileData()
    {
        string streamming_path = Application.streamingAssetsPath;
        string persistent_path =  Application.persistentDataPath;
    }
}
